package com.google.gwt.sample.dynatablerf.client.presenters;

import java.util.Set;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.sample.dynatablerf.shared.GrifoRequestFactory;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
import com.google.web.bindery.requestfactory.shared.EntityProxy;
import com.google.web.bindery.requestfactory.shared.RequestContext;

public abstract class MultipleSelectionDataPresenter<T extends EntityProxy, E extends RequestContext>
		extends AbstractSearchDataPresenter<T, E> {

	public interface MultipleSelectionDataDisplay<T extends EntityProxy>
			extends SearchDataDisplay<T> {

		Set<T> getSelectedSet();
	}

	public MultipleSelectionDataPresenter(EventBus eventBus,
			GrifoRequestFactory requestFactory) {
		super(eventBus, requestFactory);
	}

	@Override
	protected void bind() {
		super.bind();

		getMultipleSelectionDataDisplay().getSelectionChangedHandlers()
				.addSelectionChangeHandler(new Handler() {

					@Override
					public void onSelectionChange(SelectionChangeEvent event) {
						onMultipleSelection(getMultipleSelectionDataDisplay()
								.getSelectedSet());
					}
				});
	}

	@Override
	protected SearchDataDisplay<T> getSearchDataDisplay() {
		return getMultipleSelectionDataDisplay();
	}

	protected abstract MultipleSelectionDataDisplay<T> getMultipleSelectionDataDisplay();

	protected abstract void onMultipleSelection(Set<T> selectedSet);

}
